<template>
  <div class="company-container">
    <!--    搜索框和添加按钮-->
    <div class="operation-panel">
      <el-button type="primary" @click="handleAdd">添加公司</el-button>
      <div class="search-box">
        <el-input v-model="searchKeyword"
                  placeholder="请输入公司名称"
                  clearable
                  @clear="handleSearch"
                  @keyup.enter.native="handleSearch">
          <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>
        </el-input>
      </div>
    </div>

    <!-- 数据表格 -->
    <el-table
        v-loading="loading"
        :data="companyList"
        border
        stripe
        style="width: 100%"
        height="calc(100vh - 220px)"
    >
      <el-table-column prop="id" label="ID" width="80" align="center"></el-table-column>
      <el-table-column prop="name" label="公司名称" min-width="180"></el-table-column>
      <el-table-column prop="establishmentDate" label="成立日期" width="140" align="center">
        <template slot-scope="scope">
          {{ formatDate(scope.row.establishmentDate) }}
        </template>
      </el-table-column>
      <el-table-column prop="registeredCapital" label="注册资本(万元)" width="140" align="right">
        <template slot-scope="scope">
          {{ formatCapital(scope.row.registeredCapital) }}
        </template>
      </el-table-column>
      <el-table-column prop="operating" label="运营状态" width="120" align="center">
        <template slot-scope="scope">
          <el-tag :type="scope.row.operating ? 'success' : 'danger'">
            {{ scope.row.operating ? '运营中' : '已停业' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="handleEdit(scope.row)"
          >编辑
          </el-button>
          <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDelete(scope.row.id)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <div class="pagination-container">
      <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pagination.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagination.total"
      ></el-pagination>
    </div>

    <!-- 添加/编辑对话框 -->
    <CompanyForm
        v-model="dialogVisible"
        :title="dialogTitle"
        :formData="formData"
        @submit="handleFormSubmit"
        @reset="resetFormData"
    />
  </div>
</template>

<script>
import Handler from './Company.js'

export default Handler
</script>

<style scoped lang="scss">
@import './Company.scss';
</style>
